package com.yazi.mxz.common.db.dao.impl;

import java.util.HashMap;
import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.yazi.mxz.common.db.dao.MemberRoleDao;
import com.yazi.mxz.common.entity.beans.MemberRole;
import com.yazi.mxz.common.entity.beans.MemberRoleId;

import com.myframework.smhj.hibernate.dao.BasicDao;

@Repository("memberRoleDao")
public class MemberRoleDaoImpl extends BasicDao<MemberRole> implements MemberRoleDao {

	
	public MemberRoleDaoImpl() {
		super(MemberRole.class);
		
	}

	@Override
	public Criteria getExample(MemberRole mr, String searchWord) {
		Criteria c = super.getExample(mr, searchWord);
		
		// 关联对象条件
		if (null != mr) {
			// ID
			MemberRoleId mrId = mr.getId();
			if (null != mrId) {
				if (null != mrId.getMemberId()) {
					c.add(Restrictions.eq("id.memberId", mrId.getMemberId()));
				}
				if (null != mrId.getRoleId()) {
					c.add(Restrictions.eq("id.roleId", mrId.getRoleId()));
				}
			}
			// ...其它关联对象条件
		}
		
		// ...关键字searchWord条件
		return c;
	}
	
	@Override
	public int deleteCompanyRolesForMember(long memberId, long companyId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("memberId", memberId);
		map.put("companyId", companyId);
		return executeUpdate("delCompanyRolesForMemberHql", map);
	}
	
	@Override
	public int deleteStoreRolesForMember(long memberId, long storeId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("memberId", memberId);
		map.put("storeId", storeId);
		return executeUpdate("delStoreRolesForMemberHql", map);
	}

}
